package com.darren.euc.dao.impl;


import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.darren.euc.dao.ExtensionDao;
import com.darren.euc.entity.Extension;


@Repository
public class ExtensionDaoImpl extends BaseDaoImpl<Extension, Integer> implements ExtensionDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Extension> getAllExtensions() {
		Session session = sessionFactory.getCurrentSession();	
		List<Extension> extensions = session.createQuery("from Extension order by orderNumber asc").list();
		return extensions;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Extension> getAllEnableExtensions(){
		Session session = sessionFactory.getCurrentSession();	
		List<Extension> extensions = session.createQuery("from Extension where enable = true order by orderNumber asc").list();
		return extensions;
	}
	
	
	@Override
	public Extension findByFieldName(String fieldName){
		Session session = sessionFactory.getCurrentSession();	
		Query query = session.createQuery("from Extension where extensionName = :fieldName and enable = true order by orderNumber asc");
		query.setParameter("fieldName", fieldName);
		Extension extension = (Extension) query.uniqueResult();
		return extension;
	}

}